<template>
  <div class="app">
    <div class="dafaaf">
      <div class="heads">
        <img src="@/assets/1.png" alt="">
      </div>
      <div class="aaffafff">
         <div>尝新</div>
         <div>尝热</div>
         <div>尝潮流</div>
      </div>
    </div>
    <div class="register-wrapper">
      <div id="register">
        <p class="title">商家登录</p>
        <el-form
          :model="ruleForm2"
          status-icon
          :rules="rules2"
          ref="ruleForm2"
          label-width="0"
          class="demo-ruleForm"
        >
          <el-form-item prop="tel">
            <el-input v-model="ruleForm2.tel" auto-complete="off" placeholder="请输入手机号"></el-input>
          </el-form-item>
          <el-form-item prop="pass">
            <el-input type="password" v-model="ruleForm2.pass" auto-complete="off" placeholder="输入密码"></el-input>
          </el-form-item>
          <el-alert
          v-if="loginState"
          center
          :title="msg"
          type="error"
          show-icon>
          </el-alert>
          <el-form-item>
            <el-checkbox style="float:left;line-height:20px">记住密码</el-checkbox>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="submitForm('ruleForm2')" style="width:100%;">登录</el-button>
            <div class="dolon">
                <p class="login" @click="gotoLogin">没有账号？立即注册</p>
                <p class="login" @click="$router.push('/forgetPassword')">忘记密码</p>
            </div>
          </el-form-item>
        </el-form>
      </div>
    </div>
  </div>
</template>
<script>
import {sogin} from '@/apiUrl/busslogin'
export default {
  name: "Register",
  data() {
    // <!--验证手机号是否合法-->
    let checkTel = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请输入手机号码'))
      } else if (!this.checkMobile(value)) {
        callback(new Error('手机号码不合法'))
      } else {
        callback()
      }
    }
    // <!--验证密码-->
    let validatePass = (rule, value, callback) => {
      if (value === "") {
        callback(new Error("请输入密码"))
      } else {
        callback()
      }
    };
    return {
      qqdata:'',
      ruleForm2: {
        pass: "",
        tel: "",
      },
      rules2: {
        pass: [{ validator: validatePass, trigger: 'change' }],
        tel: [{ validator: checkTel, trigger: 'change' }],
      },
      flag: true,
      businessId:0,             // 商家id主账号就直接是自己的id，子账号是父类id，登录查询时时先看父类id有无值，有的话就是子账号，没有的话就是主键id
      businessSubAccountId:0,  // 账号id
      businessState:0,         //账号角色id
      loginState:false,        //控制登录失败提示
      msg:"",                  //登录失败错误文本
    }
  },
  mounted() {
    this.qqlog()
  },
  methods: {
    // <!--提交登录-->
    submitForm(formName) {
      let _th = this;
      var data ={
        mobile : this.ruleForm2.tel,
        password : this.ruleForm2.pass
      }
      this.$refs[formName].validate(valid => {
        if (valid) {
          console.log(1)
          console.log(sogin)
          sogin(data).then(res=>{
            this.$message({
              message: res.data.msg,
              type: 'success'
            });
            this.$store.commit("SET_SESSIONID",res.data.data.sessionId)
            this.$store.commit("SET_BUSINESSID",res.data.data.businessId)
            this.$router.push({
              path: "/business"
            });
          })
        } else {
          this.$message.error('登录失败');
          console.log("error submit!!");
          return false;
        }
      })
    },
    // <!--进入注册页-->
    gotoLogin() {
      this.$router.push({
        path: "/merchantRegister"
      });
    },

    // 验证手机号
    checkMobile(str) {
      let re = /^1\d{10}$/
      if (re.test(str)) {
        return true;
      } else {
        return false;
      }
    },
    qqlog(){
      // let _this = this
      // axios.get('http://111.229.104.2:8066/base/login/h5/getQOpenid')
      // .then(function (res) {
      //   _this.qqdata = res.data.body;
      //   console.log(res.data.body);
      // })
    }
  }
};
</script>

<style scoped>
.app{
  width: 100%;
  height: 100%;
  margin: 0px;
  padding: 0px;
}
.dafaaf{
  width: 100%;
  height: 108px;
  background-color: #fff;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-sizing: border-box;
}
.heads {
  width: 239px;
  height: 100%;
  margin-left: 109px;
}
.heads img{
  width: 100%;
  margin-top: 24px;
}
.aaffafff {
  width: 223px;
  display: flex;
  justify-content: space-between;
  margin-right: 200px;
}
.aaffafff div {
  font-size: 24px;
  line-height: 100px;
  color: #EC8741;
  margin-top: 20px;
}

.register-wrapper{
  width: 100%;
  position: absolute;
  top: 108px;
  bottom: 0px;
  left: 0px;
  background: url(../assets/loginBg.png) no-repeat center center;
  background-size: 100% 100%;
}
.register-wrapper img {
  position: absolute;
  z-index: 1;
}

#register {
    max-width: 340px;
    background: #fff;
    padding: 20px 40px;
    border-radius: 10px;
    position: absolute;
    z-index: 9;
    top: 190px;
    right: 150px;
}
.title {
  font-size: 26px;
  line-height: 50px;
  font-weight: bold;
  margin: 10px;
  text-align: center;
}
.el-form-item {
  text-align: center;
}
.login {
  margin-top: 10px;
  font-size: 14px;
  line-height: 22px;
  color: #1ab2ff;
  cursor: pointer;
  text-align: left;
  text-indent: 8px;
  width: 160px;
}
.login:hover {
  color: #2c2fd6;
}
.code >>> .el-form-item__content {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.code button {
  margin-left: 20px;
  width: 140px;
  text-align: center;
}
.el-button--primary:focus {
  background: #409EFF;
  border-color: #409EFF;
  color: #fff;
}
.dolon {
    display: flex;
    justify-content: space-between;
    width: 430px;
}
</style>
